package com.gifts.ui.page.common;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import com.gifts.service.FacebookService;
import com.gifts.service.FacebookService.FacebookServiceListener;
import com.gifts.ui.page.login.FacebookLoginPage;
import com.gifts.ui.page.login.loading.LoadingPage;
/**
 * GiftMainPage for Facebook GiftAFriend APp
 * 
 * @author kcui
 *
 */
public class GiftMainPage  extends Composite implements FacebookServiceListener {
	private FacebookService facebookService = FacebookService.getInstance();
	
	private StackLayout layout;
	public GiftMainPage(Composite arg0, int arg1) {
		super(arg0, arg1);
		
//		RowLayout rowLayout = new RowLayout();
//		 setLayout(rowLayout);
		 setLayoutData( new RowData(600,100));
		
	   // setLayoutData(new GridData(GridData.FILL));
	    layout = new StackLayout();
	    
	    setLayout(layout);
	    setSize(600, 500);
	    layout.topControl =  new  LoadingPage(this, SWT.NONE);
	    facebookService.addFaceBookListener(this);
	    facebookService.checkAuthenticate();
	   // showSelectAfriendsPage();
//	  
	   
	 
	}
	
	
	/**
	 * ShowFaceBookLoginPage
	 */
	public void showFacebookLoginPage() {
		Control[] childrens = getChildren();
		for(Control children: childrens) {
			children.dispose();
		}
		layout.topControl = PageFactory.createPage(PageFactory.FACEBOOK_LOGIN_PAGE, this, SWT.NONE);
		
	}
	
	/**
	 * show SelectAFriendsPage
	 */
	public void showSelectAfriendsPage() {
		Control[] childrens = getChildren();
		for(Control children: childrens) {
			children.dispose();
		}
		layout.topControl = PageFactory.createPage(PageFactory.SELECT_A_FRIEND_PAGE, this,SWT.NONE);
		//layout.topControl.setSize(1024, 700);
		layout.topControl.redraw();
		//setSize(1024, 700);
		getParent().redraw();
		update();
		getParent().update();
		redraw();
		
		
		
		
	}


	@Override
	public void onAuthenticateReqired() {
		showFacebookLoginPage();
		
	}


	@Override
	public void onAuthenticateCompleted() {
		showSelectAfriendsPage();
		
	}


	@Override
	public void onLogout() {
		
		
	}

}
